function Watcher(vm, exp, cb) {
  this.cb = cb;
  this.exp = exp;
  this.vm = vm;
  this.value = this.get();
}

Watcher.prototype = {
  get() {
    Dep.target = this;
    const value = this.vm.data[this.exp]; // 执行get函数
    Dep.target = null;
    return value;
  },
  update() {
    this.run();
  },
  run() {
    const value = this.vm.data[this.exp];
    const oldVal = this.value;
    if (value === oldVal) return;
    this.value = value;
    this.cb.call(this.vm, value, oldVal);
  }
};
